package com.example.springmvc.controller;

import com.example.springmvc.entities.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.ui.Model;
import org.thymeleaf.util.StringUtils;

@Controller
public class UserController {

    @RequestMapping(value = "/")
    public String index(){
        return "register.html";
    }

    @PostMapping(value = "/register")
    public String DoRegister(@ModelAttribute("form") User user, Model model){
        model.addAttribute("user",user);
        if (!StringUtils.isEmpty(user.getUsername()) && !StringUtils.isEmpty(user.getPassword())){
            return "success";
        }else {
            return "register";
        }
    }


}
